
all: clean A4 test
	
A4:
	bison interpreter.ypp # to create C++ file interpreter.tab.cpp
	bison -d program.y # to create header file program.tab.h for lexer
	flex program.l
	gcc -c lex.yy.c # create the object file lex.yy.o
	g++ interpreter.tab.cpp program.cpp lex.yy.o -o interpreter # create the object file lex.yy.o 

tests: A4
	cp samples/factorial.p tests/factorial.p
	./interpreter < samples/factorial.p > tests/factorial.ram
	./interpreter -memory < samples/factorial.p > tests/factorial.mem
	./interpreter -optimize < samples/factorial.p > tests/factorialopt.ram
	./interpreter -optimize -memory < samples/factorial.p > tests/factorialopt.mem
	cp samples/if.p tests/if.p
	./interpreter < samples/if.p > tests/if.ram
	./interpreter -memory < samples/if.p > tests/if.mem
	./interpreter -optimize < samples/if.p > tests/ifopt.ram
	./interpreter -optimize -memory < samples/if.p > tests/ifopt.mem
	cp samples/while.p tests/while.p
	./interpreter < samples/while.p > tests/while.ram
	./interpreter -memory < samples/while.p > tests/while.mem
	./interpreter -optimize < samples/while.p > tests/whileopt.ram
	./interpreter -optimize -memory < samples/while.p > tests/whileopt.mem
	cp samples/fibonacci.p tests/fibonacci.p
	./interpreter < samples/fibonacci.p > tests/fibonacci.ram
	./interpreter -memory < samples/fibonacci.p > tests/fibonacci.mem
	./interpreter -optimize < samples/fibonacci.p > tests/fibonacciopt.ram
	./interpreter -optimize -memory < samples/fibonacci.p > tests/fibonacciopt.mem
	cp samples/ytox.p tests/ytox.p
	./interpreter < samples/ytox.p > tests/ytox.ram
	./interpreter -memory < samples/ytox.p > tests/ytox.mem
	./interpreter -optimize < samples/ytox.p > tests/ytoxopt.ram
	./interpreter -optimize -memory < samples/ytox.p > tests/ytoxopt.mem
	cp samples/samplefile.p tests/samplefile.p
	./interpreter < samples/samplefile.p > tests/samplefile.ram
	./interpreter -memory < samples/samplefile.p > tests/samplefile.mem
	./interpreter -optimize < samples/samplefile.p > tests/samplefileopt.ram
	./interpreter -optimize -memory < samples/samplefile.p > tests/samplefileopt.mem
	
clean:
	rm -rf *o lect2b*
	rm -rf *.tab.*
	rm -rf lex.yy.c
	rm -rf interpreter
	rm -rf tprog
	rm -rf tstmt
	rm -rf tstmtlist
	rm -rf tests/*

buildtest1:
	g++ program.cpp unittests/tprog.cpp -o unittests/tprog # create the object file lex.yy.o 

test1:
	unittests/./tprog

buildtest2:
	g++ program.cpp unittests/tstmt.cpp -o unittests/tstmt # create the object file lex.yy.o 

test2:
	unittests/./tstmt

buildtest3:
	g++ program.cpp unittests/tstmtlist.cpp -o unittests/tstmtlist # create the object file lex.yy.o 

test3:
	unittests/./tstmtlist